package com.markerhub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.markerhub.entity.Link;
import com.markerhub.entity.User;
import com.markerhub.mapper.LinkMapper;
import com.markerhub.mapper.UserMapper;
import com.markerhub.service.LinkService;
import com.markerhub.service.UserService;
import javafx.scene.chart.PieChart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {
      @Autowired
      LinkMapper linkMapper;

      @Override
      public List<Link> getLinkList()
      {
          QueryWrapper<Link> queryWrapper=new QueryWrapper<>();
          queryWrapper.orderByAsc("create_time");
          return linkMapper.selectList(queryWrapper);
      }

      @Override
      public void addLink(String linkName,String avatarLink,String blogLink,String description)
      {
          Date data=new Date();
          ZoneId zoneId = ZoneId.systemDefault();
          LocalDateTime localDateTime = LocalDateTime.ofInstant(data.toInstant(), zoneId);
          Link link=new Link();
          link.setLinkName(linkName);
          link.setAvatarLink(avatarLink);
          link.setBlogLink(blogLink);
          link.setDescription(description);
          link.setCreateTime(localDateTime);
          linkMapper.insert(link);
      }
}
